import Mustache from "mustache";

function testOne() {
  const template = `
  <ul>
    {{#list}}
        <li>{{name}}</li>
    {{/list}}
   </ul>`;
  const data = {
    list: [
      {
        name: "apple",
      },
      {
        name: "pear",
      },
    ],
  };

  const result = Mustache.render(template, data);
  console.log("🚀 ~ main ~ result:", result);

  const result2 = Mustache.render("<span>{{#list}}{{.}}{{/list}}</span>", {
    list: ["张三", "李四", "王五"],
  });
  console.log("🚀 ~ testOne ~ result2:", result2);

  const result3 = Mustache.render("<span>{{#list}}{{info}}{{/list}}</span>", {
    list: [{ name: "张三" }, { name: "李四" }, { name: "王五" }],
    info() {
      return this.name + ",";
    },
  });
  console.log("🚀 ~ testOne ~ result3:", result3);

  const result4 = Mustache.render(
    "<span>{{#show}}显示{{/show}}{{^show}}隐藏{{/show}}</span>",
    {
      show: false,
    }
  );
  console.log("🚀 ~ testOne ~ result4:", result4);

  const result5 = Mustache.render("<span>{{&key}}</span>", {
    key: "<span>标题</span>",
  });
  console.log("🚀 ~ testOne ~ result5:", result5);
}

function mustacheTest() {
  testOne();
}

export default mustacheTest;
